package jmine.tec.report.impl.table;

import java.io.Serializable;

import jmine.tec.report.api.RendererParameters;
import jmine.tec.report.api.table.ReportCell;
import jmine.tec.report.impl.RendererParametersImpl;

/**
 * Implementação padrão de célula de tabela
 * 
 * @author lundberg
 */
public class ReportCellImpl implements ReportCell, Serializable {

    private final Object value;

    private String rendererType;

    private RendererParameters parameters;

    /**
     * Construtor
     * 
     * @param value value
     */
    public ReportCellImpl(Object value) {
        this.value = value;
        this.parameters = new RendererParametersImpl();
    }

    /**
     * {@inheritDoc}
     */
    public String getRendererType() {
        if (this.rendererType == null) {
            this.rendererType = "string";
        }
        return this.rendererType;
    }

    /**
     * {@inheritDoc}
     */
    public void setRendererType(String rendererType) {
        this.rendererType = rendererType;
    }

    /**
     * {@inheritDoc}
     */
    public Object getValue() {
        return this.value;
    }

    /**
     * {@inheritDoc}
     */
    public String getStringValue() {
        if (this.value == null) {
            return null;
        } else {
            return this.value.toString();
        }
    }

    /**
     * {@inheritDoc}
     */
    public ReportCell copy(Object newValue) {
        ReportCellImpl copy = new ReportCellImpl(newValue);
        copy.setRendererType(this.rendererType);
        copy.parameters = this.parameters.clone();
        return copy;
    }

    /**
     * {@inheritDoc}
     */
    public RendererParameters getParameters() {
        return this.parameters;
    }
}
